import $http from "@/ajax/http.js";

export const exit = {
	data() {
		return {
			token: wx.getStorageSync('token')
		}
	},
	methods: {
		handleExit() {
			wx.showModal({
				title: "退出登录",
				content: "请您确定是否退出？",
				success: res => {
					if (res.confirm) {
						this.logout();
					}
				}
			});
		},
		logout() {
			$http.request({
				header:{
					Authorization:this.token
				},
				url: "/common/weichat/auth/loginOut",
				method: "POST"
			}).then((res) => {
				wx.redirectTo({
					url: '/pages/users/login/index'
				});

				wx.removeStorageSync('token');
				wx.removeStorageSync('userRole');
			}).catch((error) => {
				console.error("Logout failed: ", error);
			})
		},
	}
}